package vip.finance.makemoney.config.feign;

import feign.codec.Decoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.util.List;

/**
 * @author yangbin
 * @since 2023-02-08
 */
@Configuration
public class FeignJsonConfiguration {
    @Bean
    public Decoder textPlainDecoder() {
        MessageConverter wxConverter = new MessageConverter();
        ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(wxConverter);
        return new SpringDecoder(objectFactory);
    }

    static class MessageConverter extends MappingJackson2HttpMessageConverter {
        public MessageConverter() {
            super.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN, MediaType.TEXT_HTML));
        }
    }
}
